Imports Microsoft.VisualBasic

Public Class clsExport
    Public Sub XmlToXlsx(ByVal SourceFilePath As String, ByVal OutFileName As String)
        Dim oExcel As Object = CreateObject("Excel.Application")
        Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
        Dim oBook As Object = oExcel.Workbooks.Open(SourceFilePath)
        Dim oSheet As Object = oBook.Worksheets(1)
        Dim TempFilePath As String = SourceFilePath & ".xlsx"

        oBook.SaveAs(FileName:=TempFilePath, FileFormat:=51)
        oBook.Close()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
        oBook = Nothing
        oExcel.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
        oExcel = Nothing
        GC.Collect()
        GC.WaitForPendingFinalizers()
        System.IO.File.Delete(SourceFilePath)
        System.Threading.Thread.CurrentThread.CurrentCulture = oldCI

        Dim ms As IO.MemoryStream = New IO.MemoryStream(IO.File.ReadAllBytes(TempFilePath))
        Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.xlsx", OutFileName))
        Response.BinaryWrite(ms.ToArray())
        ms.Close()
        ms.Dispose()
        System.IO.File.Delete(TempFilePath)
        Response.End()
    End Sub
End Class
